<?php

/*
 * @copyright :     Ienter asia Technologies
 * @author :        Quyet
 * @version         v.1.0
 * @created         24/6/2014
 * @Description :   Controller PIT info
 */
if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Mod_pitinfo extends MYAD_Controller {

    function __construct() {
        parent::__construct();
        $this->load->model('Mmod_pitinfo', 'pi');
    }

    function index($page = 0) {
        $employeeID = $this->input->post('txtEmployeeId');
        $data = $this->pi->getAllData($employeeID, $page);
        $this->load->view('layout', $data);
    }

    function updatePITInfo() {
        $employeeID = $this->input->post('txtEmployeeId');
        $pitInfoId = $this->input->post('txtPITInfoId');
        /* check exists */

        $pitInfo = TRUE;
        if ($pitInfoId) {
            $pitInfo = $this->pi->getPITInforByID($employeeID, $pitInfoId);
        }
        if (!$pitInfo || !$employeeID) {
            redirect('/employee');
        }
        $temp = array();
        /* check submit */
        if (isset($_POST['btnSubmit'])) {
            $validateFlag = $this->pi->validate();
            if ($validateFlag) {
                /* validate success */
                $id = $this->input->post('txtEmployeeId');
                $temp = $this->pi->updatePITInfo($employeeID, $pitInfoId);
            }
        }

        $data = $this->pi->getAddPITInfo($employeeID, $pitInfoId);
        $this->load->view('layout', array_merge($data, $temp));
    }

}

?>